//引入请求数据模块
import req from "../req.js";

//获取用户信息
export function getUserInfo(  ){
    return new Promise(function( resolve , reject ){
        
        req.request({
            baseurl: process.env.VUE_APP_HOST,
            url: "/user/userInfo",
            method:"get",
            header:{
                token: localStorage.getItem('token'),
                "Content-Type":"application/json;charset=utf-8"}
        }).then( res=>{
            resolve( res );
        } ).catch( err =>{
            reject( err );
        });
    });
}

//设置用户头像
export function setUserAvatar( adata ){
    return new Promise(function( resolve , reject ){
        
        req.request({
            baseurl: process.env.VUE_APP_HOST,
            url: "/user/setAvatar",
            method:"post",
            data: adata,
            header:{
                token: localStorage.getItem('token'),
                "Content-Type":"application/json;charset=utf-8"}
        }).then( res=>{
            resolve( res );
        } ).catch( err =>{
            reject( err );
        });
    });
}

//设置用户昵称
export function setUserNickName( adata ){
    return new Promise(function( resolve , reject ){
        
        req.request({
            baseurl: process.env.VUE_APP_HOST,
            url: "/user/setNickName",
            method:"post",
            data: adata,
            header:{
                token: localStorage.getItem('token'),
                "Content-Type":"application/json;charset=utf-8"}
        }).then( res=>{
            resolve( res );
        } ).catch( err =>{
            reject( err );
        });
    });
}

//修改密码
export function changeUserPwd( adata ){
    return new Promise(function( resolve , reject ){
        
        req.request({
            baseurl: process.env.VUE_APP_HOST,
            url: "/user/changePwd",
            method:"post",
            data: adata,
            header:{
                token: localStorage.getItem('token'),
                "Content-Type":"application/json;charset=utf-8"}
        }).then( res=>{
            resolve( res );
        } ).catch( err =>{
            reject( err );
        });
    });
}

//安全退出
export function userLogout(  ){
    return new Promise(function( resolve , reject ){
        
        req.request({
            baseurl: process.env.VUE_APP_HOST,
            url: "/user/logOut",
            method:"get",
            header:{
                token: localStorage.getItem('token'),
                "Content-Type":"application/json;charset=utf-8"}
        }).then( res=>{
            resolve( res );
        } ).catch( err =>{
            reject( err );
        });
    });
}